package com.summer.config.custom.configuration;

import lombok.Data;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.List;
import java.util.Map;

@Data
@Configuration
@PropertySource(name = "spelProperties", value = "classpath:spelconfig.properties", encoding = "utf-8")
@ToString
public class SpELConfig {

    @Value("#{'${user.names}'.split(',')}") // list
    private List<String> userNames;

    @Value("#{${user.ages}}") // map
    private Map<String, Integer> ages;

    @Value("#{'${user.names}'.split(',')[0]}") // list.get(0)
    private String firstName;

    @Value("#{${user.ages}.zhangsan}")
    private String age;

    @Value("#{${user.ages}['fff'] ?: 44}") // ?和:之间不能有空格
    private String fffAge;

    @Value("#{systemProperties['java.home']}") // java home
    private String javeHome;
}
